#coding:utf8
from myBuf import *
from defaultChi import *
fileName = 'tangshi.txt'
fileName = 'ss.txt'
try:
    f = open(fileName)
    rr = f.read()
    f.close()
except:
    f = open(fileName,'rb')
    rr = f.read()
    f.close()    
    rr = rr.decode(encoding='utf8')

m = {'1':'一','2':'二','3':'三','4':'四','5':'五','6':'六','7':'七','8':'八',
     '9':'九','0':'零'}
r = ''.join(m.values())+'爨'

def int2chi(co):
    co = co%1000
    co = str(co)
    s = ''
    for i in co:
        s += m[i]
    return s+'爨'

import string
lettersAndDigits = string.ascii_letters + string.digits+string.punctuation +' \n\r'
lettersAndDigits =' 　\n\r\t'
for i in rr:
    if i in lettersAndDigits:
        continue
    r += i
    
s = set()
for i in r:
    if i not in s:
        s.add(i)
        if len(s)==4*1024:
            break
print(len(s))  
co = 0
for i in defaultChi:
    co += 1
    if len(s)==4*1024:
        print(co)
        break    
    if i not in s:
        s.add(i)       
print(len(s))   

to = defaultChi
to = ''.join(s)
print(to)

toL = defaultDamList
toL = []
co = 0
st = int2chi(co)
for i in r:
    if i not in to:
        i = to[0]
    st += i
    if len(st)>50:
        toL.append(st+'爨')
        co += 1
        st = int2chi(co)
if st:
    toL.append(st+'爨')    
print(len(toL))    

st = to.encode(encoding='utf8')
w = structWrapper()
w.writeWord(len(st))
w.writeArr(st)

for one in toL:
    st = one.encode(encoding='utf8')
    w.writeWord(len(st))
    w.writeArr(st)    
f = open('file.txt','wb')
f.write(w.data)
f.close()
import shutil
shutil.copyfile('file.txt','d:/binary/file.txt')
